package cn.cdnsu.org.service.impl;

import cn.cdnsu.base.service.impl.IBaseServiceImpl;
import cn.cdnsu.org.domain.Department;
import cn.cdnsu.org.mapper.DepartmentMapper;
import cn.cdnsu.org.service.IDepartmentServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class DepartmentServiceImplI extends IBaseServiceImpl<Department> implements IDepartmentServiceI {

    @Autowired
    private DepartmentMapper mapper;
//    @Override
//    @Transactional
//    public void update1(Department department) {
//        Long id = department.getParent().getId();
//        if (Objects.isNull(id)){
//            department.setPath("/"+department.getId());
//        }else{
//            Department parent = mapper.selectById(id);
//            department.setPath(parent.getPath()+"/"+department.getId());
//        }
//        mapper.update(department);
//    }
//
//    @Override
//    @Transactional
//    public void insert1(Department department) {
//        mapper.insert(department);
//        //处理path
//        Long id = department.getParent().getId();
//        if (Objects.nonNull(id)){
//            Department parent = mapper.selectById(id);
//            department.setPath(parent.getPath()+"/"+department.getId());
//        }else{
//            department.setPath("/"+department.getId());
//        }
//        mapper.update(department);
//    }

    @Override
    public List<Department> deptTree() {
        return mapper.deptTree();
    }
}
